<?php

/*
 * This file is part of the Geek-Zoo Projects.
 *
 * @copyright (c) 2010 Geek-Zoo Projects More info http://www.geek-zoo.com
 * @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License
 * @author quqiang <quqiang@geek-zoo.com>
 *
 */

require ROOT_PATH.'/Helper/front_abstract.php';

class Action extends front_abstract
{
    function index()
    {
        $post_id = _GET('post_id', 0);
        if (!$post_id) {
            die(0);
        }
        $data = _model('comment')->getList("WHERE post_id=$post_id AND status='0' ORDER BY add_time DESC", new Pager(10));
        $this->view->assign($data);
        $this->view->display('front/comment.html');
    }
    
    function create()
    {
        //if (!$_SESSION['user']) {
        //    die('2');
        //}
	   
	 $content = strip_tags(_POST('content'));

	
        $post_id = _POST('post_id');
        if (!$content || !$post_id) {
            die('0');
        }
        $post_info = _model('post')->read(array('id'=>$post_id));
        if (empty($post_info)) {
            die('');
        }
	$user_id = $this->info['id'];
	// if(empty($user_id)){
	// 	
	// 	// if(strlen($content) > 30){
	// 	// 
	// 	// 	die('88');	
	// 	// }
	// }

	if(strlen($content) < 18){

		die('100');	
	}


        $time = time();
        
        $check_content = filter_content($content);
        if ($check_content) {
            die('3');
        }
        
        $id = _model('comment')->create(array('content'=>$content, 'post_id'=>$post_id, 'user_id'=>$user_id, 'add_time'=>$time));
        if ($id) {
		_model('post')->update(array('id'=>$post_info['id']), array('comment_num'=>$post_info['comment_num']+1, 'hotcolor_num'=>$post_info['hotcolor_num']+2));

            die('1');
        }
        
    }
}


?>
